<template>
  <!--首页轮播图组件-->
    <div class="slideshow">
        <el-carousel :interval="3000" type="card" height="250px" :initial-index="0">
            <el-carousel-item v-for="item in bannerImg" :key="item.bannerId">
                <a :href="item.src" class="slideshow-item">
                    <h3 :style="{'background-color':item.titleColor}">{{ item.titleType }}</h3>
                    <el-image
                            :src="item.img"
                            fit="cover">
                    </el-image>
                </a>
            </el-carousel-item>
        </el-carousel>
    </div>
</template>

<script>
import {publicFun} from "@/mixin";
import {getFindPage} from "@/http";

export default {
    name: "Carousel",
    data() {
        return {
            bannerImg: []
        }
    },
    beforeCreate() {
        // 加载发现页内容，但是只加载banner部分
        getFindPage().then(res => {
            if (res.code === 200) {
                const bannerData = res.data.blocks[0]
                this.bannerImg = bannerData.extInfo.banners.map(item => {
                    // console.log(item)
                    return {
                        bannerId: item.bannerId,
                        img: item.pic,
                        titleColor: item.titleColor,
                        titleType: item.typeTitle,
                        src: item.url
                    }
                })
            } else {
                console.log("轮播图请求失败")
            }
        }, err => {
            console.log(`轮播图请求失败${err}`)
        })
    }
}
</script>

<style scoped lang="less">
.slideshow {

  //轮播图部分
  .slideshow-item {
    display: block;
    position: relative;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    .el-image {
      width: 100%;
      height: 100%
    }

    //轮播图右下角图片
    h3 {
      position: absolute;
      bottom: -5px;
      right: 0;
      color: white;
      font-weight: 600;
      font-size: 14px;
      padding: 5px 5px 5px 12px;
      border-radius: 15px 0 0 15px;
      z-index: 999;
      background-color: red;
    }
  }
}


</style>